import json
from pyecharts import options as opts
from pyecharts.charts import Bar
# from pyecharts.faker import Faker
#
# print(Faker.choose())
# print(Faker.values())
# print(Faker.values())

# 1 读取文件
with open('C:/Users/Administrator/Desktop/课上练习/python成绩.txt', mode='r', encoding='utf-8') as file:
    content = file.read()

# 2 将文本字符串转换成python能识别的数据类型
content = json.loads(content)
# 针对字典数据分别取值，键名，键值
keys = content.keys()
values = content.values()
print(keys)
print(values)

# 3 找合适的柱状图
Bar().add_xaxis(list(keys)).add_yaxis("python成绩", list(values)).set_global_opts(
    title_opts=opts.TitleOpts(title='23大数据', subtitle='python成绩', pos_left='center'),
    toolbox_opts=opts.ToolboxOpts(),
    legend_opts=opts.LegendOpts(is_show=False),
).render("23大数据的成绩.html")

